﻿using BLL;
using Common;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public partial class CateringLoginForm : Form
    {
        UserInfo userInfo = new UserInfo();
        CateringBLL cateringBLL = new CateringBLL();
        public CateringLoginForm()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            UserIoginForm userIoginForm = new UserIoginForm();
            userIoginForm.ShowDialog();
        }

        private void CateringLoginForm_Load(object sender, EventArgs e)
        {
            //初始化验证码
            Bitmap bitmap = CodeHelper.GetCode();
            pictureBox1.Image = bitmap;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = CodeHelper.GetCode();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //获取用户输入的用户名和密码
            string username = textBox1.Text;
            string password = MD5Helper.GetMD5(textBox2.Text);

            //验证验证码是否正确
            if (textBox3.Text == CodeHelper.codes)
            {
                //启动登录功能,调用DLL
                
                userInfo.Username = username;
                userInfo.Password = password;

                if(cateringBLL.CateringLogin(userInfo) == 0)
                {
                    //登录成功，打开主界面
                    CateringMainForm cateringMainForm = new CateringMainForm(this);
                    cateringMainForm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("账号或密码错误");
                }
            }
            else
            {
                MessageBox.Show("验证码有误");
            }
        }
    }
}
